package com.pdwl.cashoutpay.util;


import net.sf.json.JSONObject;

import java.util.*;

public class Sign {
    public static String getSign(JSONObject json) throws Exception {
        String sign = "";

        SortedMap map=new TreeMap();
        StringBuffer sb = new StringBuffer();
        Iterator it = json.keys();
        while (it.hasNext()) {
            String k = (String) it.next();
            String v = json.getString(k);
            map.put(k,v);
        }

        Set es=map.entrySet();
        Iterator it1=es.iterator();
        while (it1.hasNext()){
            Map.Entry entry= (Map.Entry) it1.next();
            String k= (String) entry.getKey();
            String v= (String) entry.getValue();
            if(!"sign".equals(k)&&null!=v&&!"".equals(v)&&!"key".equals(k)){
                sb.append(k+"="+v+"&");
            }
        }

        sign = EncryptionUntil.getMD5(sb.substring(0,sb.length()-1).getBytes());
        return sign;
    }

}
